/*  HostMon/msntop - A simple program to monitor hosts on android
	Copyright (C) 2009 Devendra Laulkar

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation version 2 of the License. 

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.android.msntop;


import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Settings extends Activity {

	private Button set;
	public static final String PREFS_NAME = "sntop_pref";
	public static final String DEFAULT_USER_KEY = "defaultUser";
	public static final String XML_WEBPATH = "xml_webpath";
	//	private String details[];

	protected void onCreate(Bundle savedInstance)
	{

		super.onCreate(savedInstance);
		setContentView(R.layout.settings);
		set = (Button) findViewById(R.id.settingsConfirm);
		
		SharedPreferences settings = getSharedPreferences(Settings.PREFS_NAME, 0);
		String user = settings.getString(Settings.DEFAULT_USER_KEY, "root");
		final TextView tv = (TextView) findViewById(R.id.defaultUser);
		tv.setText(user);
		
		String xmlPath = settings.getString(Settings.XML_WEBPATH, getResources().getText(R.string.default_xml_webpath).toString());
		final TextView xmltv = (TextView) findViewById(R.id.xml_webpath);
		
		xmltv.setText(xmlPath);
		
		if(set == null)
		{
			Log.e("Settings:onCreate()","Unable to get the confirm button");

		}
		else
			set.setOnClickListener(new View.OnClickListener() {

				public void onClick(View view) {

					String text;
					SharedPreferences settings = getSharedPreferences(Settings.PREFS_NAME, 0);

					SharedPreferences.Editor editor = settings.edit();
					 text = tv.getText().toString();
					text = text.trim();
					Log.i("Settings", "User changed to "+text);
					editor.putString(DEFAULT_USER_KEY, text);
					
					// For the xml path
					
					text = xmltv.getText().toString();
					text = text.trim();
					Log.i("Settings", "Xml path changed to "+text);
					editor.putString(XML_WEBPATH, text);
										
					editor.commit();

					finish();
				}

			});


	}


}